Remove dependency on time in favor of std::time
authorDemur Rumed <gunkmute@gmail.com>
Sat, 14 May 2016 14:08:48 +0000 (14:08 +0000)
committerDemur Rumed <gunkmute@gmail.com>
Sat, 14 May 2016 14:10:07 +0000 (14:10 +0000)
Cargo.lock
Cargo.toml
src/cargo/lib.rs
src/cargo/util/profile.rs

index fb69826cecacd8ddb6c5ee9f33f630f387bc00dc..aab3cb77dd61b500ab4af5320508c221f591ee7f 100644 (file)
@@ -28,7 +28,6 @@ dependencies = [
  "tar 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "tempdir 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "time 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)",
  "toml 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)",
  "url 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -414,16 +413,6 @@ dependencies = [
  "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
-[[package]]
-name = "time"
-version = "0.1.34"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
- "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
 [[package]]
 name = "toml"
 version = "0.1.28"
index c3a4c48c2a3388c0833338536ecd499bd4961645..6560c9ee320aad00d8b2d5ae3ffcd2519e49d98f 100644 (file)
@@ -41,7 +41,6 @@ semver = "0.2.2"
 tar = "0.4"
 tempdir = "0.3"
 term = "0.4.4"
-time = "0.1"
 toml = "0.1"
 url = "1.1"
 winapi = "0.2"
index c1012bc40d0aa4186b83f06c5d0d0fdc1d1e3b72..c20b150dfcda5ef40c945ea0b1cc8d8dd1282c9e 100644 (file)
@@ -22,7 +22,6 @@ extern crate semver;
 extern crate tar;
 extern crate tempdir;
 extern crate term;
-extern crate time;
 extern crate toml;
 extern crate url;
 
index 59cc83f45dc73733749d5d732865ee6de1880d90..5810f51836935d4cc4ec6c0f6e1fdbd3133a0804 100644 (file)
@@ -1,11 +1,11 @@
 use std::env;
 use std::fmt;
 use std::mem;
-use time;
+use std::time;
 use std::iter::repeat;
 use std::cell::RefCell;
 
-thread_local!(static PROFILE_STACK: RefCell<Vec<u64>> = RefCell::new(Vec::new()));
+thread_local!(static PROFILE_STACK: RefCell<Vec<time::Instant>> = RefCell::new(Vec::new()));
 thread_local!(static MESSAGES: RefCell<Vec<Message>> = RefCell::new(Vec::new()));
 
 type Message = (usize, u64, String);
@@ -21,7 +21,7 @@ fn enabled_level() -> Option<usize> {
 pub fn start<T: fmt::Display>(desc: T) -> Profiler {
     if enabled_level().is_none() { return Profiler { desc: String::new() } }
 
-    PROFILE_STACK.with(|stack| stack.borrow_mut().push(time::precise_time_ns()));
+    PROFILE_STACK.with(|stack| stack.borrow_mut().push(time::Instant::now()));
 
     Profiler {
         desc: desc.to_string(),
@@ -36,7 +36,8 @@ impl Drop for Profiler {
         };
 
         let start = PROFILE_STACK.with(|stack| stack.borrow_mut().pop().unwrap());
-        let end = time::precise_time_ns();
+        let duration = start.elapsed();
+        let duration_ms = duration.as_secs() * 1000 + (duration.subsec_nanos() / 1000000) as u64;
 
         let stack_len = PROFILE_STACK.with(|stack| stack.borrow().len());
         if stack_len == 0 {
@@ -47,7 +48,7 @@ impl Drop for Profiler {
                     if l != lvl { continue }
                     println!("{} {:6}ms - {}",
                              repeat("    ").take(lvl + 1).collect::<String>(),
-                             time / 1000000, msg);
+                             time, msg);
 
                     print(lvl + 1, &msgs[last..i], enabled);
                     last = i;
@@ -56,14 +57,14 @@ impl Drop for Profiler {
             }
             MESSAGES.with(|msgs_rc| {
                 let mut msgs = msgs_rc.borrow_mut();
-                msgs.push((0, end - start,
+                msgs.push((0, duration_ms,
                            mem::replace(&mut self.desc, String::new())));
                 print(0, &msgs, enabled);
             });
         } else {
             MESSAGES.with(|msgs| {
                 let msg = mem::replace(&mut self.desc, String::new());
-                msgs.borrow_mut().push((stack_len, end - start, msg));
+                msgs.borrow_mut().push((stack_len, duration_ms, msg));
             });
         }
     }